<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // 命名捕获分组
    let str = '<a href="https://www.baidu.com">百度一下</a>'
    const reg = /<a href="(.*)">(.*)<\/a>/
    const result = reg.exec(str)
    console.log(result);
    // [
    //     '<a href="https://www.baidu.com">百度一下</a>',
    //     'https://www.baidu.com',
    //     '百度一下',
    //     index: 0,
    //     input: '<a href="https://www.baidu.com">百度一下</a>',
    //     groups: undefined
    // ]
    // 命令捕获分组写法
    console.log(result[1], result[2]);
    const reg2 = /<a href="(?<url>.*?)">(?<name>.*?)<\/a>/g;
    let result2 = reg2.exec(str);
    console.log(result2, result2.groups.url, result2.groups.name);

</script>

</html>